package GameMain.Model
{
	import Engine.Module.ModuleBase;
	import Engine.Module.ModuleManager;
	
	import GameMain.Game;
	import GameMain.Macro.Macro;
	import GameMain.Macro.MacroEvent;
	
	import Interface.Common.IGuiManager;
	
	import library.SocketData.SocketData;
	
	public class GuiManager extends ModuleManager implements IGuiManager
	{
		private var _currentModule:String = null;
		private var _placeStateDict:Object = {};
		
		public function GuiManager()
		{
			super();
			this._placeStateDict[Macro.MODULE_GAME_EREA] = 1;
			this._placeStateDict[Macro.MODULE_ROOM_LIST] = 2;
		}
		
		public function showGameErea():void
		{
			this.clearAllUI();
			this._currentModule = Macro.MODULE_GAME_EREA;
			this.showModule(Macro.MODULE_GAME_EREA);
			this.showModule(Macro.MODULE_CHAT);
			this.getModule(Macro.MODULE_CHAT)["showChatHall"]();
			this.showModule(Macro.MODULE_TOOL_BAR);
			this.sendPlaceToServer(this._currentModule);
			
		}
		
		private function sendPlaceToServer(modelName:String):void
		{
			var data:SocketData = new SocketData();
			data.writeInt8(this._placeStateDict[modelName]);
			Game.EngineMgr.sendMessageData(MacroEvent.MSG_TO_SERVER_CHANGE_PLACE,data);
		}
		
		
		public function showGameWait():void
		{
			this.clearAllUI();
			this.showModule(Macro.MODULE_WAIT_GAME);
			this.showModule(Macro.MODULE_CHAT);
			this.getModule(Macro.MODULE_CHAT)["showChatHall"]();
			
			
		}
		
		public function showRoomList():void
		{
			this.clearAllUI();
			this._currentModule = Macro.MODULE_ROOM_LIST;
			this.showModule(Macro.MODULE_ROOM_LIST);
			this.showModule(Macro.MODULE_CHAT);
			this.showModule(Macro.MODULE_TOOL_BAR);
			this.sendPlaceToServer(this._currentModule);
		}
		
		public function showRoom():void
		{
			this.clearAllUI();
			this._currentModule = Macro.MODULE_ROOM;
			this.showModule(Macro.MODULE_ROOM);
			this.showModule(Macro.MODULE_CHAT);
			this.showModule(Macro.MODULE_TOOL_BAR);
		}
		
		public function showPVPGame():void
		{
			this.clearAllUI();
			this._currentModule = Macro.MODULE_PVP_GAME;
			this.showModule(Macro.MODULE_PVP_GAME);
		}
		
		
		public function showBebug():void
		{
			this.showModule(Macro.MODULE_DEBUG);
		}
		
		public function showLogin():void
		{
			this.clearAllUI();
			this._currentModule = Macro.MODULE_LOGIN;
			this.showModule(Macro.MODULE_LOGIN);
		}
		
		public function showBackWND():void
		{
			switch(this._currentModule)
			{
				case Macro.MODULE_GAME_EREA:
					Game.ShowMsg("确定要退出游戏？",null,2);
					break;
				case Macro.MODULE_ROOM:
					
					this.showRoomList();
					break;
				case Macro.MODULE_ROOM_LIST:
					this.showGameErea();
					break;
			}
		}
	}
}